package com.chilly.other.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Chilly Cui on 2020/11/27.
 */
public class ArrayListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("a1");
        list.add("a2");
        list.add("a3");
        list.add("a4");
        System.out.println("list1:" + list);

        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            String str = it.next();            //此处引发 java.util.ConcurrentModificationException异常
            if (str.equals("a3")) {
                //list.add("a99");
            }
        }
        System.out.println("list2:" + list);
    }

}
